#pragma once

#include <cstdint>
#include <ostream>
#include <vector>

class Rects {
public:
    Rects() = default;
    Rects(int32_t x, int32_t y, int32_t w, int32_t h);
    virtual ~Rects() = default;

    int32_t GetNumber() const;
    int32_t GetX(int32_t index) const;
    int32_t GetY(int32_t index) const;
    int32_t GetW(int32_t index) const;
    int32_t GetH(int32_t index) const;

    Rects operator -(Rects &other);
    Rects &operator -=(Rects &other);
    friend std::ostream &operator <<(std::ostream &os, const Rects &rects);

private:
    struct Rect {
        int32_t x;
        int32_t y;
        int32_t w;
        int32_t h;
    };
    static void Intersect(const struct Rect &a, const struct Rect &b, struct Rect &out);
    static void Subtrace(const struct Rect &rect, const struct Rect &inner, std::vector<struct Rect> &rects);
    static void RectsSubtrace(std::vector<struct Rect> &lrects, std::vector<struct Rect> rrects);

    std::vector<struct Rect> rects;
};
